package com.scm.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.scm.common.core.domain.entity.SysUser;
import com.scm.common.utils.DateUtils;
import com.scm.common.utils.StringUtils;
import com.scm.persist.model.ScmProject;
import com.scm.persist.model.ScmProjectExample;
import com.scm.persist.mybatis.ScmProjectMapper;
import com.scm.service.IScmProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.scm.common.core.text.Convert;

/**
 * 项目Service业务层处理
 *
 * @author reptilemanager
 * @date 2024-04-20
 */
@Service
public class ScmProjectServiceImpl implements IScmProjectService
{
    @Autowired
    private ScmProjectMapper scmProjectMapper;

    /**
     * 查询项目
     *
     * @param id 项目主键
     * @return 项目
     */
    @Override
    public ScmProject selectScmProjectById(Long tenantId,Long id)
    {
        return scmProjectMapper.selectByPrimaryKey(tenantId,id);
    }

    /**
     * 查询项目列表
     *
     * @param scmProject 项目
     * @return 项目
     */
    @Override
    public List<ScmProject> selectScmProjectList(ScmProject scmProject)
    {
        ScmProjectExample example = new ScmProjectExample();
        ScmProjectExample.Criteria criteria = example.createCriteria();
        return   scmProjectMapper.selectByExample(example);
    }

    /**
     * 新增项目
     *
     * @param scmProject 项目
     * @return 结果
     */
    @Override
    public int insertScmProject(ScmProject scmProject, SysUser sysUser)
    {
        scmProject.setCreateTime(System.currentTimeMillis());
        scmProject.setCreateUser(sysUser.getUserName());
        return scmProjectMapper.insertSelective(scmProject);
    }

    /**
     * 修改项目
     *
     * @param scmProject 项目
     * @return 结果
     */
    @Override
    public int updateScmProject(ScmProject scmProject,SysUser sysUser)
    {
        scmProject.setUpdateTime(System.currentTimeMillis());
        scmProject.setUpdateUser(sysUser.getUserName());
        return scmProjectMapper.updateByPrimaryKey(scmProject);
    }

    /**
     * 批量删除项目
     *
     * @param ids 需要删除的项目主键
     * @return 结果
     */
    @Override
    public int deleteScmProjectByIds(String ids)
    {
        if (StringUtils.isEmpty(ids)) {
            return 0;
        }
        String[] split = ids.split(",");
        List<Long> idlist = new ArrayList<>();
        for (String s : split) {
            idlist.add(Long.valueOf(s));
        }
        ScmProjectExample example = new ScmProjectExample();
        example.createCriteria().andIdIn(idlist);
        return  scmProjectMapper.deleteByExample(example);
    }

    /**
     * 删除项目信息
     *
     * @param id 项目主键
     * @return 结果
     */
    @Override
    public int deleteScmProjectById(Long id)
    {
        return scmProjectMapper.deleteByPrimaryKey(id);
    }
}
